package com.hongxinguoji.manager.job.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.quartz.ee.jmx.jboss.JBoss4RMIRemoteMBeanScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hongxinguoji.manager.common.util.EasyUIDataGridResult;
import com.hongxinguoji.manager.common.util.HXResult;
import com.hongxinguoji.manager.job.pojo.HxJob;
import com.hongxinguoji.manager.job.service.IJobService;

@Controller
@RequestMapping("/job")
public class JobController {

	@Autowired
	private IJobService jobService;

	/**
	 * index
	 * 
	 * @param path
	 * @return
	 */
	@RequestMapping("/{path}")
	public String showPage(@PathVariable String path) {
		return "job/" + path;
	}

	@RequestMapping("/list")
	@ResponseBody
	public EasyUIDataGridResult getList(Integer page, Integer rows) {
		EasyUIDataGridResult result = jobService.getList(page, rows);
		return result;

	}

	@RequestMapping("/saveJob")
	@ResponseBody
	public HXResult saveJob(HxJob job, String content, HttpServletRequest request) throws ParseException {

		if (job.getIspush() == 1) {
			Date date = new Date();
			job.setJobPushtime(date);
		}
		return jobService.add(job, content);
	}

	@RequestMapping("/delete")
	@ResponseBody
	public HXResult delete(String ids) {
		return jobService.deleteOrRestore(ids, 0);
	}

	@RequestMapping("/update")
	@ResponseBody
	public HXResult updateJob(HxJob job) {
		jobService.update(job);

		return HXResult.ok();

	}

	@RequestMapping("/restore")
	@ResponseBody
	public HXResult restoreArticle(String ids) {
		return jobService.deleteOrRestore(ids, 1);
	}

}
